package com.eastcom.dataquality.core.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.eastcom.dataquality.core.module.Atom_AbnormalScanJob;

public class ScanJobDao extends JdbcDaoSupport implements RowMapper<Atom_AbnormalScanJob>{

	public Atom_AbnormalScanJob findById(String dataset_id){
		String sql="select * from QA_ABNORMALSCAN_JOB where DATASET_ID=?";
		List<Atom_AbnormalScanJob> results=getJdbcTemplate().query(sql, new Object[]{dataset_id}, this);
		return results.get(0);
	}

	public List<Atom_AbnormalScanJob> findAll(){
		String sql="select * from QA_ABNORMALSCAN_JOB where DATASET_ID in(select distinct(ID) from QA_DATASET_DEFINE)";
		return getJdbcTemplate().query(sql, this);
	}
	
	public Atom_AbnormalScanJob mapRow(ResultSet rs, int rowNum) throws SQLException {
		Atom_AbnormalScanJob ret=new Atom_AbnormalScanJob();
		ret.setDataSetId(rs.getString("DATASET_ID"));
		ret.setFirstTime(rs.getTimestamp("FIRST_TIME"));
		ret.setEndTime(rs.getTimestamp("END_TIME"));
		ret.setBackScanHour(rs.getInt("BACKSCAN_HOUR"));
		ret.setRepeatNum(rs.getInt("REPEAT_NUM"));
		ret.setInterval(rs.getLong("INTERVAL"));
		ret.setVersion(rs.getInt("VERSION"));
		return ret;
	}
}
